<?php

use yii\helpers\Html;
use yii\widgets\DetailView;

/* @var $this yii\web\View */
/* @var $model backend\modules\home\models\Booklist */

$this->title = $model->backend_title;
$this->params['breadcrumbs'][] = ['label' => '漫画列表', 'url' => ['index']];
$this->params['breadcrumbs'][] = $this->title;
$photos = $model->getPhotolist();
?>
<div class="booklist-view">

    <p>
        <?= Html::a('编辑', ['update', 'id' => $model->id], ['class' => 'btn btn-info']) ?>
        <?php if($model->type == 1){ ?>
            <?= Html::a('上传图片', ['upload', 'id' => $model->id], ['class' => 'btn btn-info']) ?>
        <?php }else{ ?>
            <?= Html::a('添加子集', ['create', 'id' => $model->id], ['class' => 'btn btn-info']) ?>
            <?= Html::a('上传封面图片', ['upload-cover', 'id' => $model->id], ['class' => 'btn btn-info']) ?>
        <?php }?>
        <?= Html::a('删除', ['delete', 'id' => $model->id], [
            'class' => 'btn btn-danger',
            'data' => [
                'confirm' => 'Are you sure you want to delete this item?',
                'method' => 'post',
            ],
        ]) ?>
    </p>

    <div class="row">
        <div class="col-md-6">
            <div class="panel panel-info">
                <div class="panel-heading">详情</div>

                <?= DetailView::widget([
                    'model' => $model,
                    'attributes' => [
                        'id',
                        [
                            'format' => 'raw',
                            'attribute' => 'cid',
                            'value' => function($model) {
                                $m = \common\components\Tools::getCateInfo($model->cid);
                                return $m->title;
                            },
                        ],
                        'parent_id',
                        [
                            'format' => 'raw',
                            'attribute' => 'type',
                            'value' => function($model) {
                                if($model->type == 1){
                                    return '<span class="btn btn-xs btn-primary">单行本</span>';
                                }else{
                                    return '<span class="btn btn-xs btn-primary">多行本</span>';
                                }
                            },
                        ],
                        'number',
                        'front_title',
                        'backend_title',
                        [
                            'format' => 'raw',
                            'attribute' => 'thumb_img',
                            'value' => function($model) {
                                if($model->thumb_img){
                                    return '<img src="'.$model->thumb_img.'" style="width:100px;">';
                                }else{
                                    return '';
                                }
                            },
                        ],
                        'cont_num',
                        'click_num',
                        'zan_num',
                        'intro',
                        [
                            'format' => 'raw',
                            'attribute' => 'is_recommend',
                            'value' => function($model) {
                                if($model->is_recommend == 1){
                                    return '<span class="btn btn-xs btn-success">是</span>';
                                }else{
                                    return '<span class="btn btn-xs btn-danger">否</span>';
                                }
                            },
                        ],
                        [
                            'format' => 'raw',
                            'attribute' => 'is_hot',
                            'value' => function($model) {
                                if($model->is_hot == 1){
                                    return '<span class="btn btn-xs btn-success">是</span>';
                                }else{
                                    return '<span class="btn btn-xs btn-danger">否</span>';
                                }
                            },
                        ],
                        [
                            'format' => 'raw',
                            'attribute' => 'is_over',
                            'value' => function($model) {
                                if($model->is_over == 1){
                                    return '<span class="btn btn-xs btn-warning">已完结</span>';
                                }else{
                                    return '<span class="btn btn-xs btn-primary">连载中</span>';
                                }
                            },
                        ],
                        [
                            'format' => 'raw',
                            'attribute' => 'is_advert',
                            'value' => function($model) {
                                if($model->is_advert == 1){
                                    return '<span class="btn btn-xs btn-warning">已投放广告</span>';
                                }else{
                                    return '<span class="btn btn-xs btn-primary">未投放广告</span>';
                                }
                            },
                        ],
                        [
                            'format' => 'raw',
                            'attribute' => 'is_free',
                            'value' => function($model) {
                                if($model->is_free == 1){
                                    return '<span class="btn btn-xs btn-warning">收费可看</span>';
                                }else{
                                    return '<span class="btn btn-xs btn-primary">免费</span>';
                                }
                            },
                        ],
                        'mark',
                        'remark',
                        'date',
                        [
                            'format' => 'raw',
                            'attribute' => 'status',
                            'value' => function($model) {
                                if($model->status == 1){
                                    return '<span class="btn btn-xs btn-success">已上架</span>';
                                }else{
                                    return '<span class="btn btn-xs btn-danger">已下架</span>';
                                }
                            },
                        ],
                        [
                            'format' => 'raw',
                            'attribute' => 'create_at',
                            'value' => function($model) {
                                return date('Y-m-d H:i', $model->create_at);
                            },
                        ],
                    ],
                ]) ?>

            </div>
        </div>

        <div class="col-md-6">
            <div class="panel panel-info" style="background: #333;">
                <div class="panel-heading">图片 <?=count($photos)?> p</div>
                <div class="row" style="padding:0px 10px 10px 10px">

                    <?php foreach($photos as $k=>$v){ ?>
                        <?php if(($k + 1)%4 == 1){ ?>
                            <div class="col-md-3 col1" style="margin-top: 10px">
                                <div>
                                    <img src="<?php echo $v['path']?>" alt="" style="width:100%;border-top-left-radius:6px;border-top-right-radius:6px;">
                                </div>
                                <div style="padding: 10px 10px 5px 10px;background: #fff;border-bottom-right-radius: 6px;border-bottom-left-radius: 6px;">
                                    <p><?php echo basename($v['path'])?></p>
                                    <?php if($v['type'] != 1){?>
                                        <p><a class="btn btn-xs btn-info" href="/home/book/set-cover-photo?id=<?=$v['id']?>">设为封面</a></p>
                                    <?php }else{ ?>
                                        <p><a class="btn btn-xs btn-danger" href="/home/book/set-cover-photo?id=<?=$v['id']?>">取消设为封面</a></p>
                                    <?php }?>
                                    <?php if($v['sort'] != 1){?>
                                        <p><a class="btn btn-xs btn-info" href="/home/book/set-photo-sort?id=<?=$v['id']?>">置顶</a></p>
                                    <?php }else{ ?>
                                        <p><a class="btn btn-xs btn-danger" href="/home/book/set-photo-sort?id=<?=$v['id']?>">已置顶</a></p>
                                    <?php }?>
                                    <p><a class="btn btn-xs btn-danger" href="/home/book/delete-photo?id=<?=$v['id']?>">删除</a></p>
                                </div>
                            </div>
                        <?php }else if(($k + 1)%4 == 2){ ?>

                            <div class="col-md-3 col2" style="margin-top: 10px">
                                <div>
                                    <img src="<?php echo $v['path']?>" alt="" style="width:100%;border-top-left-radius:6px;border-top-right-radius:6px;">
                                </div>
                                <div style="padding: 10px 10px 5px 10px;background: #fff;border-bottom-right-radius: 6px;border-bottom-left-radius: 6px;">
                                    <p><?php echo basename($v['path'])?></p>
                                    <?php if($v['type'] != 1){?>
                                        <p><a class="btn btn-xs btn-info" href="/home/book/set-cover-photo?id=<?=$v['id']?>">设为封面</a></p>
                                    <?php }else{ ?>
                                        <p><a class="btn btn-xs btn-danger" href="/home/book/set-cover-photo?id=<?=$v['id']?>">取消设为封面</a></p>
                                    <?php }?>
                                    <?php if($v['sort'] != 1){?>
                                        <p><a class="btn btn-xs btn-info" href="/home/book/set-photo-sort?id=<?=$v['id']?>">置顶</a></p>
                                    <?php }else{ ?>
                                        <p><a class="btn btn-xs btn-danger" href="/home/book/set-photo-sort?id=<?=$v['id']?>">已置顶</a></p>
                                    <?php }?>
                                    <p><a class="btn btn-xs btn-danger" href="/home/book/delete-photo?id=<?=$v['id']?>">删除</a></p>
                                </div>
                            </div>
                        <?php }else if(($k + 1)%4 == 3){ ?>

                            <div class="col-md-3 col3" style="margin-top: 10px">
                                <div>
                                    <img src="<?php echo $v['path']?>" alt="" style="width:100%;border-top-left-radius:6px;border-top-right-radius:6px;">
                                </div>
                                <div style="padding: 10px 10px 5px 10px;background: #fff;border-bottom-right-radius: 6px;border-bottom-left-radius: 6px;">
                                    <p><?php echo basename($v['path'])?></p>
                                    <?php if($v['type'] != 1){?>
                                        <p><a class="btn btn-xs btn-info" href="/home/book/set-cover-photo?id=<?=$v['id']?>">设为封面</a></p>
                                    <?php }else{ ?>
                                        <p><a class="btn btn-xs btn-danger" href="/home/book/set-cover-photo?id=<?=$v['id']?>">取消设为封面</a></p>
                                    <?php }?>
                                    <?php if($v['sort'] != 1){?>
                                        <p><a class="btn btn-xs btn-info" href="/home/book/set-photo-sort?id=<?=$v['id']?>">置顶</a></p>
                                    <?php }else{ ?>
                                        <p><a class="btn btn-xs btn-danger" href="/home/book/set-photo-sort?id=<?=$v['id']?>">已置顶</a></p>
                                    <?php }?>
                                    <p><a class="btn btn-xs btn-danger" href="/home/book/delete-photo?id=<?=$v['id']?>">删除</a></p>
                                </div>
                            </div>
                        <?php }else{ ?>

                            <div class="col-md-3 col4" style="margin-top: 10px">
                                <div>
                                    <img src="<?php echo $v['path']?>" alt="" style="width:100%;border-top-left-radius:6px;border-top-right-radius:6px;">
                                </div>
                                <div style="padding: 10px 10px 5px 10px;background: #fff;border-bottom-right-radius: 6px;border-bottom-left-radius: 6px;">
                                    <p><?php echo basename($v['path'])?></p>
                                    <?php if($v['type'] != 1){?>
                                        <p><a class="btn btn-xs btn-info" href="/home/book/set-cover-photo?id=<?=$v['id']?>">设为封面</a></p>
                                    <?php }else{ ?>
                                        <p><a class="btn btn-xs btn-danger" href="/home/book/set-cover-photo?id=<?=$v['id']?>">取消设为封面</a></p>
                                    <?php }?>
                                    <?php if($v['sort'] != 1){?>
                                        <p><a class="btn btn-xs btn-info" href="/home/book/set-photo-sort?id=<?=$v['id']?>">置顶</a></p>
                                    <?php }else{ ?>
                                        <p><a class="btn btn-xs btn-danger" href="/home/book/set-photo-sort?id=<?=$v['id']?>">已置顶</a></p>
                                    <?php }?>
                                    <p><a class="btn btn-xs btn-danger" href="/home/book/delete-photo?id=<?=$v['id']?>">删除</a></p>
                                </div>
                            </div>
                        <?php }?>

                    <?php }?>
                </div>
            </div>
        </div>

    </div>

</div>
